/**
 * 
 */
package poc.android.explistview;

import java.util.List;
import java.util.Map;

import poc.android.util.POCApplication;
import poc.android.weather.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;

/**
 * TODO
 * 
 * ADD BACK VALIDATE+SAVE LOGIC
 * ADD BACK THE CLOSING PAGE LOGIC (REALLY FINISH METHOD OR OTHER METHODS?)
 * 
 * LIST PAGE:
 * 	ADD BACK ON-RESUME LOGIC
 * 
 * @author kusanagihk<br/>
 * created at: Oct 15, 2011::12:04:12 AM
 */
public class NoMoreExpBrandsPageActivity extends Activity {

	POCApplication mApplication;
	LinearLayout mLayout;
	Button mBtnDone;
	
	/**
	 * {@inheritDoc}
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.no_more_exp_brands_page_activity);
		
		this.mApplication=(POCApplication) this.getApplication();
		
		// do validation + update the POCApplication entry
	}
	
	/**
	 * {@inheritDoc}
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		this.setupWidgets();
	}

	/**
	 * helper to setup the widget(s) in the activity
	 */
	@SuppressWarnings("unchecked")
	private void setupWidgets() {
		Map<String, Object> aMap=null;
		List<String> aBrandsList=null;
		
		aMap=this.mApplication.getApplicationProperty(POCApplication.APP_NO_MORE_EXP);
		this.mLayout=(LinearLayout) this.findViewById(R.id.llNoExpBrandsContainer);
		
		this.mBtnDone=(Button) this.findViewById(R.id.btnNoExpBrandsDone);
		this.mBtnDone.setOnClickListener(new Button.OnClickListener(){
			/**
			 * {@inheritDoc}
			 */
			public void onClick(View arg0) {
// TODO Auto-generated method stub
				
			}}
		);
		aBrandsList=(List<String>) aMap.get(NoMoreExpandableListViewActivity.NO_MORE_EXP_BRANDS_LIST);
		if (aBrandsList!=null && this.mLayout!=null) {
			this.createCheckboxFromList(aBrandsList);
		}
	}
	
	/**
	 * dynamically create CheckBox(s) views to the LinearLayout... 
	 * randomly checking the checkboxes... (current based on the 0, 4, 9th index)
	 * @param pList
	 */
	private void createCheckboxFromList(final List<String> pList) {
		// try dynamic create CheckBox.... id=brandId... or id={n}-brandId
		for (int i=0; i<pList.size(); i++) {
			String aId=pList.get(i);
			CheckBox aCBox=new CheckBox(this);
			
			aCBox.setText(aId);
			if (i==0 || i==9 || i==4) {
				aCBox.setChecked(true);
			}
			this.mLayout.addView(aCBox);
		}
	}

}
